package com.yz.android_baozou.helper;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by Administrator on 2016/10/31.
 */

public class OkhttpHelper {
    public static OkhttpHelper okhttpHelper;
    private static OkHttpClient mOkhttpClient;

    public static OkhttpHelper getIntecer() {
        if (okhttpHelper == null) {
            okhttpHelper = new OkhttpHelper();
        }
        return okhttpHelper;
    }

    public static String getStringFromUrl(String path) {
        try {
            OkHttpClient client = new OkHttpClient();
            Request request = new Request.Builder().url(path).build();
            Call call = client.newCall(request);
            Response response = call.execute();
            return response.body().string();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static OkHttpClient getOkHttpSingletonInstance() {
        if (mOkhttpClient == null) {
            synchronized (OkHttpClient.class) {
                mOkhttpClient = new OkHttpClient();
            }
        }
        return mOkhttpClient;
    }
}
